Sams Publishing : Programming in Objective-C by By
Author:By
Language: eng
Format: epub
ISBN: 0-672-32586-1
Publisher: Sams Publishing
Program 13.13
#import <stdio.h> void copyString (char *to, char *from) { for ( ; *from != '\0'; ++from, ++to ) *to = *from; *to = '\0'; } int main (int argc, char *argv[]) { void copyString (char *to, char *from); char string1[] = "A string to be copied."; char string2[50]; copyString (string2, string1); printf ("%s\n", string2); copyString (string2, "So is this."); printf ("%s\n", string2); return 0; }
Program 13.13 Output
A string to be copied. So is this.
The copyString function defines the two formal parameters, to and from, as character pointers and not as character arrays as was done in the previous version of copyString. This reflects how these two variables will be used by the function.
A for loop is then entered (with no initial conditions) to copy the string pointed to by from into the string pointed to by to. Each time through the loop, the from and to pointers are each incremented by one. This sets the from pointer pointing to the next character that is to be copied from the source string and sets the to pointer pointing to the location in the destination string where the next character is to be stored.
When the from pointer points to the null character, the for loop is exited. The function then places the null character at the end of the destination string.
In the main routine, the copyString function is called twicethe first time to copy the contents of string1 into string2 and the second time to copy the contents of the constant character string "So is this." into string2.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(26291)
Hello! Python by Anthony Briggs(25216)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(24446)
Kotlin in Action by Dmitry Jemerov(23536)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(22880)
Dependency Injection in .NET by Mark Seemann(22667)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(21431)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(20273)
Grails in Action by Glen Smith Peter Ledbrook(19343)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17056)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(16366)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(14077)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(12255)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11533)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10643)
Hit Refresh by Satya Nadella(9220)
The Kubernetes Operator Framework Book by Michael Dame(8579)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8432)
Robo-Advisor with Python by Aki Ranin(8376)